import React from 'react'
import { Menu } from 'antd'
import { history } from 'umi';

//定义用于接收选中的数组
let selectItem;

class MenuGeneral extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            selectedKeys: [],
        }
    }

    //遍历数据找key值
    findkey = (subMenuList, key) => {
        return subMenuList.map((item) => {
            if (item.key === key) {
                selectItem = item;
                return false;
            } else {
                if (item.children) {
                    this.findkey(item.children, key);
                }
            }
        });
    };

    onSelect = ({ key }) => {
        //路由跳转
        console.log(key);
        history.push(key);
        this.setState({
            selectedKeys: [key],
        });
    };

    render() {
        console.log('this.props', this.props)
        return (
            <Menu
                onSelect={this.onSelect}
                {...this.props}
            >
                {this.props.children}
            </Menu>
        )
    }
}

export default MenuGeneral

